<template>
  <a-modal v-model="visible" :mask-closable="false" width="80%" title="查看" :dialog-style="{ top: '20px' }" :footer="null">
    <div v-if="visible" v-permission="['push-order:query']" v-loading="loading">
      <a-descriptions bordered :xs="4" :sm="2" :md="2">
        <a-descriptions-item label="ID" :span="2">
          {{ formData.id }}
        </a-descriptions-item>
        <a-descriptions-item label="商户ID" :span="2">
          {{ formData.mchId }}
        </a-descriptions-item>
        <a-descriptions-item label="应用ID" :span="2">
          {{ formData.appId }}
        </a-descriptions-item>
        <a-descriptions-item label="渠道" :span="2">
          {{ formData.channel }}
        </a-descriptions-item>
        <a-descriptions-item label="外部单号" :span="2">
          {{ formData.outerNo }}
        </a-descriptions-item>
        <a-descriptions-item label="批次号" :span="2">
          {{ formData.batchNo }}
        </a-descriptions-item>
        <a-descriptions-item label="业务ID" :span="4">
          {{ formData.bizId }}
        </a-descriptions-item>
        <a-descriptions-item label="渠道参数" :span="4">
          {{ formData.channelParams }}
        </a-descriptions-item>
        <a-descriptions-item label="附加参数1" :span="4">
          {{ formData.param1 }}
        </a-descriptions-item>
        <a-descriptions-item label="附加参数2" :span="4">
          {{ formData.param2 }}
        </a-descriptions-item>
        <a-descriptions-item label="扩展参数" :span="4">
          {{ formData.extra }}
        </a-descriptions-item>
        <a-descriptions-item label="通知URL" :span="4">
          {{ formData.notifyUrl }}
        </a-descriptions-item>
        <a-descriptions-item label="渠道响应数据" :span="4">
          {{ formData.channelResp }}
        </a-descriptions-item>
        <a-descriptions-item label="单据类型" :span="2">
          {{ $enums.PUSH_ORDER_TYPE.getDesc(formData.orderType) }}
        </a-descriptions-item>
        <a-descriptions-item label="状态" :span="2">
          {{ $enums.PUSH_ORDER_STATUS.getDesc(formData.status) }}
        </a-descriptions-item>
        <a-descriptions-item label="创建时间" :span="2">
          {{ formData.createTime }}
        </a-descriptions-item>
        <a-descriptions-item label="修改时间" :span="2">
          {{ formData.updateTime }}
        </a-descriptions-item>
        <a-descriptions-item label="成功时间" :span="2">
          {{ formData.successTime }}
        </a-descriptions-item>
        <a-descriptions-item label="失败时间" :span="2">
          {{ formData.failureTime }}
        </a-descriptions-item>
        <a-descriptions-item label="失败原因" :span="4">
          {{ formData.errorMsg }}
        </a-descriptions-item>
      </a-descriptions>
    </div>
  </a-modal>
</template>
<script>
export default {
  // 使用组件
  components: {
  },

  props: {
    id: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      // 是否可见
      visible: false,
      // 是否显示加载框
      loading: false,
      // 表单数据
      formData: {}
    }
  },
  created() {
    this.initFormData()
  },
  methods: {
    // 打开对话框 由父页面触发
    openDialog() {
      this.visible = true

      this.$nextTick(() => this.open())
    },
    // 关闭对话框
    closeDialog() {
      this.visible = false
      this.$emit('close')
    },
    // 初始化表单数据
    initFormData() {
      this.formData = {
        id: '',
        appId: '',
        channel: '',
        outerNo: '',
        batchNo: '',
        bizId: '',
        channelParams: '',
        param1: '',
        param2: '',
        extra: '',
        notifyUrl: '',
        channelResp: '',
        orderType: '',
        status: '',
        createTime: '',
        updateTime: '',
        successTime: '',
        failureTime: '',
        errorMsg: ''
      }
    },
    // 页面显示时触发
    open() {
      // 初始化数据
      this.initFormData()

      // 查询数据
      this.loadFormData()
    },
    // 查询数据
    async loadFormData() {
      this.loading = true
      await this.$api.pushOrder.get(this.id).then(data => {
        this.formData = data
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>
